﻿using IService;
using Microsoft.AspNetCore.Mvc;

namespace XingWeiDaWMSProject.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ProductController : Controller
    {
        private readonly IProductService _productService;

        public ProductController(IProductService productService)
        {
            _productService = productService;
        }

        /// <summary>
        /// 查询货品列表（分页+筛选）
        /// </summary>
        [HttpGet("GetList")]
        public async Task<IActionResult> GetList(
            string? codeOrName = null,
            string? unit = null,
            int page = 1,
            int size = 10)
        {
            try
            {
                var result = await _productService.GetProductListAsync(codeOrName, unit, page, size);
                return Ok(new { success = true, data = result.items, total = result.total });
            }
            catch (Exception ex)
            {
                return Ok(new { success = false, message = ex.Message, data = new object[0], total = 0 });
            }
        }
    }
}
